
import java.io.*;
public class Member {
    private String number;
    private String name;
    private int age;

    public Member(String number, String name, int age){
        this.number = number;
        this.name = name;
        this.age = age;
    }
    // 部分程序代码省略，因为只一些Getter、Setter...
    @Override
    public String toString(){
        return String.format("(%s, %s, %d)", number, name, age);
    }
    public void save(){
        try(DataOutputStream output = //建立 DataOutputStream 打包 FileOutputStream
                    new DataOutputStream(new FileOutputStream(number))){
            output.writeUTF(number);
            output.writeUTF(name);
            output.writeInt(age);
        } catch(IOException ex){ //根据不同的类型调用 writeXXX()方法
            throw new RuntimeException(ex);
        }
    }
    public static Member load(String number){
        Member member = null;
        try(DataInputStream input = // 建立 DataInputStream 打包 FileInputStream
                    new DataInputStream(new FileInputStream(number))){
            member = new Member(
                    input.readUTF(), input.readUTF(), input.readInt());
        } catch(IOException ex){
            throw new RuntimeException(ex);
        }
        return member;
    }
}
